package com.szpx.mapper;

import com.szpx.entity.lkyDispatch.Delivery;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

// 标注这是一个Repository层接口
@Repository
// 标注这是一个Mapper接口
@Mapper
public interface DeliveryMapper {

    // 通过trackIngNumber获取delivery信息
    @Select("SELECT * FROM delivery WHERE trackIngNumber = #{trackingNumber}")
    Delivery getDeliveryById(Long id);

    // 获取所有delivery信息
    @Select("SELECT * FROM delivery")
    List<Delivery> getAllDeliveries();

    // 保存delivery信息
    @Insert("INSERT   INTO delivery(trackingNumber, recipient, status) VALUES(#{trackingNumber}, #{recipient}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void saveDelivery(Delivery delivery);

    // 更新delivery信息
    @Update("UPDATE delivery SET trackingNumber = #{trackingNumber}, recipient = #{recipient}, status = #{status} WHERE trackingNumber = #{trackingNumber}")
    void updateDelivery(Delivery delivery);

    // 通过id删除delivery信息
    @Delete("DELETE FROM delivery WHERE trackingNumber = #{id}")
    void deleteDeliveryById(Long id);
}
